clear all
cd "$root"
use "data_final.dta", clear

cd "$root/Tables"

/// APPENDIX TABLE A1: Summary Statistics
////////////////////////////////////////////////////////////////////////////////

est clear
estpost sum T List Knowledge Behavior c_Q4 c_Q5 c_Q4_* qualtrics urban female length_subscribe response_rate 

esttab using "sumstats.tex", refcat(T "\addlinespace[0.75em] \textbf{Main treatment variables:}" ///
	Knowledge "\midrule \textbf{Main outcome variables:}" ///
	c_Q4 "\midrule \textbf{Correct response to} \textbf{knowledge questions:} \\ \addlinespace[0.5em] \textit{Week 1:}" ///
	c_Q4_1 "\addlinespace[0.5em] \textit{Week 2:}" ///
	qualtrics "\midrule \textbf{Other variables:}", nolabel) ///
	replace cells("count(fmt(0) label({Obs.})) mean(fmt(2) label({Mean})) sd(fmt(2) label({SD})) min(fmt(2) label({Min})) max(fmt(2) label({Max}))") ///
	label f nomtitle noobs nonumber

/// APPENDIX TABLE A2: Balance
////////////////////////////////////////////////////////////////////////////////

foreach clust of varlist Week_id {

	est clear

	local bal_vars qualtrics urban female length_subscribe response_rate

	foreach var in `bal_vars' {
		eststo `var'_1: quietly areg `var' T i.Week, a(block) cluster(`clust')
		eststo `var'_2: quietly areg `var' T i.Week, a(id) cluster(`clust')
	}
	
	local names "& Qualtrics & Urban & Female & List Age & Response Rate\\" 
	local gap ""
	esttab qualtrics_1 urban_1 female_1 length_subscribe_1 response_rate_1 using balance_final.tex,  ///
		refcat(T "\textbf{Panel A:}", nolabel) ///
		nonumber replace posthead("`names'") b(2) se label ///
		alignment(S S S) f nomtitles nogaps booktabs noobs compress ///
		star(* 0.10 ** 0.05 *** 0.01) nobaselevels keep(T)
	esttab qualtrics_2 urban_2 female_2 length_subscribe_2 response_rate_2 using balance_final.tex,  ///
		refcat(T "\midrule \textbf{Panel B:}", nolabel) nonumber append posthead("`gap'") ///
		b(2) se label alignment(S S S) f nomtitles nogaps booktabs noobs compress ///
		star(* 0.10 ** 0.05 *** 0.01) nobaselevels keep(T) ///
		scalars("N_clust \hspace{0.1cm} Clusters" "N \hspace{0.1cm} Observations") sfmt(0)

}

/// APPENDIX TABLE A3: Knowledge
////////////////////////////////////////////////////////////////////////////////

foreach var in Knowledge {
	
	est clear
	local ctrl "qualtrics urban female"
	
	local opts_1 "a(block) cluster(Week_id)"
	eststo `var'_1_1: quietly areg `var' T i.Week, `opts_1'
	eststo `var'_1_2: quietly areg `var' T i.Week `ctrl', `opts_1'
	eststo `var'_1_3: quietly areg `var' T i.Week if female==1, `opts_1'
	eststo `var'_1_4: quietly areg `var' T i.Week `ctrl' if female==1, `opts_1'
	eststo `var'_1_5: quietly areg `var' T i.Week if female==0, `opts_1'
	eststo `var'_1_6: quietly areg `var' T i.Week `ctrl' if female==0, `opts_1'
	eststo `var'_1_7: quietly areg `var' T i.Week if urban==1, `opts_1'
	eststo `var'_1_8: quietly areg `var' T i.Week `ctrl' if urban==1, `opts_1'
	eststo `var'_1_9: quietly areg `var' T i.Week if urban==0, `opts_1'
	eststo `var'_1_10: quietly areg `var' T i.Week `ctrl' if urban==0, `opts_1'
	
	local opts_2 "a(id) cluster(Week_id)"
	eststo `var'_2_1: quietly areg `var' T i.Week, `opts_2'
	eststo `var'_2_2: quietly areg `var' T i.Week `ctrl', `opts_2'
	eststo `var'_2_4: quietly areg `var' T i.Week if female==1, `opts_2'
	eststo `var'_2_4: quietly areg `var' T i.Week `ctrl' if female==1, `opts_2'
	eststo `var'_2_5: quietly areg `var' T i.Week if female==0, `opts_2'
	eststo `var'_2_6: quietly areg `var' T i.Week `ctrl' if female==0, `opts_2'
	eststo `var'_2_7: quietly areg `var' T i.Week if urban==1, `opts_2'
	eststo `var'_2_8: quietly areg `var' T i.Week `ctrl' if urban==1, `opts_2'
	eststo `var'_2_9: quietly areg `var' T i.Week if urban==0, `opts_2'
	eststo `var'_2_10: quietly areg `var' T i.Week `ctrl' if urban==0, `opts_2'

}

local top "& \multicolumn{2}{c}{All} & \multicolumn{2}{c}{Female} & \multicolumn{2}{c}{Male} & \multicolumn{2}{c}{Urban} & \multicolumn{2}{c}{Rural} \\"
local lines "\cmidrule(lr{0.5em}){2-3} \cmidrule(lr{0.5em}){4-5} \cmidrule(lr{0.5em}){6-7} \cmidrule(lr{0.5em}){8-9} \cmidrule(lr{0.5em}){10-11}"
local names "& No controls & Controls & No controls & Controls & No controls & Controls& No controls & Controls& No controls & Controls  \\" 
local gap ""
esttab Knowledge_1_1 Knowledge_1_2 Knowledge_1_3 Knowledge_1_4 Knowledge_1_5 ///
	Knowledge_1_6  Knowledge_1_7 Knowledge_1_8 Knowledge_1_9 Knowledge_1_10  using "knowledge_final.tex",  ///
	refcat(T "\textbf{Panel A:}", nolabel) nonumber replace ///
	posthead("`top'" "`lines'" "`names'") b(2) se label alignment(S S S) ///
	f nomtitles nogaps booktabs noobs compress star(* 0.10 ** 0.05 *** 0.01) ///
	nobaselevels keep(T)
esttab Knowledge_2_1 Knowledge_2_2 Knowledge_2_4 Knowledge_2_4 Knowledge_2_5 ///
	Knowledge_2_6  Knowledge_2_7 Knowledge_2_8 Knowledge_2_9 Knowledge_2_10  ///
	using "knowledge_final.tex",  refcat(T "\midrule \textbf{Panel B:}", nolabel) ///
	nonumber append posthead("`gap'") b(2) se label alignment(S S S) ///
	f nomtitles nogaps booktabs noobs compress star(* 0.10 ** 0.05 *** 0.01) ///
	nobaselevels keep(T) scalars("N_clust \hspace{0.1cm} Clusters" "N \hspace{0.1cm} Observations") sfmt(0)

/// APPENDIX TABLE A4: Behavior
////////////////////////////////////////////////////////////////////////////////

foreach var in Behavior {
		
	est clear
	local ctrl "qualtrics urban female"
	
	local opts_1 "a(block) cluster(Week_id)"
	eststo `var'_1_1: quietly areg `var' 1.T##1.List i.Week, `opts_1'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'	
	eststo `var'_1_2: quietly areg `var' 1.T##1.List i.Week `ctrl', `opts_1'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_1_3: quietly areg `var' 1.T##1.List i.Week if female==1, `opts_1'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_1_4: quietly areg `var' 1.T##1.List i.Week `ctrl' if female==1, `opts_1'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_1_5: quietly areg `var' 1.T##1.List i.Week if female==0, `opts_1'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_1_6: quietly areg `var' 1.T##1.List i.Week `ctrl' if female==0, `opts_1'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_1_7: quietly areg `var' 1.T##1.List i.Week if urban==1, `opts_1'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_1_8: quietly areg `var' 1.T##1.List i.Week `ctrl' if urban==1, `opts_1'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_1_9: quietly areg `var' 1.T##1.List i.Week if urban==0, `opts_1'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_1_10: quietl areg `var' 1.T##1.List i.Week `ctrl' if urban==0, `opts_1'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	
	local opts_2 "a(id) cluster(Week_id)"
	eststo `var'_2_1: quietly areg `var' 1.T##1.List i.Week, `opts_2'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_2_2: quietly areg `var' 1.T##1.List i.Week `ctrl', `opts_2'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_2_3: quietly areg `var' 1.T##1.List i.Week if female==1, `opts_2'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_2_4: quietly areg `var' 1.T##1.List i.Week `ctrl' if female==1, `opts_2'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_2_5: quietly areg `var' 1.T##1.List i.Week if female==0, `opts_2'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_2_6: quietly areg `var' 1.T##1.List i.Week `ctrl' if female==0, `opts_2'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_2_7: quietly areg `var' 1.T##1.List i.Week if urban==1, `opts_2'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_2_8: quietly areg `var' 1.T##1.List i.Week `ctrl' if urban==1, `opts_2'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_2_9: quietly areg `var' 1.T##1.List i.Week if urban==0, `opts_2'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo `var'_2_10: quietl areg `var' 1.T##1.List i.Week `ctrl' if urban==0, `opts_2'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	
}

local top "& \multicolumn{2}{c}{All} & \multicolumn{2}{c}{Female} & \multicolumn{2}{c}{Male} & \multicolumn{2}{c}{Urban} & \multicolumn{2}{c}{Rural} \\"
local lines "\cmidrule(lr{0.5em}){2-3} \cmidrule(lr{0.5em}){4-5} \cmidrule(lr{0.5em}){6-7} \cmidrule(lr{0.5em}){8-9} \cmidrule(lr{0.5em}){10-11}"
local names "& No controls & Controls & No controls & Controls & No controls & Controls& No controls & Controls& No controls & Controls  \\" 
local gap ""
esttab Behavior_1_1 Behavior_1_2 Behavior_1_3 Behavior_1_4 Behavior_1_5 ///
	Behavior_1_6  Behavior_1_7 Behavior_1_8 Behavior_1_9 Behavior_1_10  ///
	using "behavior_final.tex",  refcat(1.T "\textbf{Panel A:}", nolabel) ///
	nonumber replace posthead("`top'" "`lines'" "`names'") b(2) se label ///
	alignment(S S S) f nomtitles nogaps booktabs noobs compress ///
	star(* 0.10 ** 0.05 *** 0.01) nobaselevels keep(1.T 1.T#1.List 1.List) 	scalars("lin_p \hspace{0.1cm} $\alpha$(Long + T $\times\$ Long > 0)") sfmt(2)

esttab Behavior_2_1 Behavior_2_2 Behavior_2_4 Behavior_2_4 Behavior_2_5 ///
	Behavior_2_6  Behavior_2_7 Behavior_2_8 Behavior_2_9 Behavior_2_10  ///
	using "behavior_final.tex",  refcat(1.T "\midrule \textbf{Panel B:}", nolabel) ///
	nonumber append posthead("`gap'") b(2) se label alignment(S S S) f ///
	nomtitles nogaps booktabs noobs compress star(* 0.10 ** 0.05 *** 0.01) ///
	nobaselevels keep(1.T 1.T#1.List 1.List) ///
	scalars("lin_p \hspace{0.1cm} $\alpha$(Long + T$\times\$Long > 0)" "N_clust \hspace{0.1cm} Clusters" "N \hspace{0.1cm} Observations") sfmt(2 0)
	
	
/// APPENDIX TABLE A5: Knowledge and Behavior By Week
////////////////////////////////////////////////////////////////////////////////
	
foreach Wk in 1 2 {
		
	local ctrl "qualtrics urban female"
	local opts_1 "a(block) cluster(Week_id)"
	eststo know_week`Wk'_1_1: quietly areg Knowledge T if Week==`Wk', `opts_1'
	eststo know_week`Wk'_1_2: quietly areg Knowledge T `ctrl' if Week==`Wk', `opts_1'
	
	eststo behavior_week`Wk'_1_1: quietly areg Behavior 1.T##1.List if Week==`Wk', `opts_1'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	eststo behavior_week`Wk'_1_2: quietly areg Behavior 1.T##1.List `ctrl' if Week==`Wk', `opts_1'
		lincom 1.List + 1.T#1.List
		estadd scalar lin_p = `r(p)'
	
}

local top "& \multicolumn{2}{c}{Week 1} & \multicolumn{2}{c}{Week 2} \\"
local lines "\cmidrule(lr{0.5em}){2-3} \cmidrule(lr{0.5em}){4-5}"
local names "& No controls & Controls & No controls & Controls \\" 
local gap ""
esttab know_week1_1_1 know_week1_1_2 know_week2_1_1 know_week2_1_2  ///
	using "By week_final.tex",  refcat(T "\textbf{Panel A:}", nolabel) ///
	nonumber replace posthead("`top'" "`lines'" "`names'") b(2) se label alignment(S S S) ///
	f nomtitles nogaps booktabs noobs compress star(* 0.10 ** 0.05 *** 0.01) ///
	nobaselevels keep(T)
esttab behavior_week1_1_1 behavior_week1_1_2 behavior_week2_1_1 behavior_week2_1_2  ///
	using "By week_final.tex",  refcat(1.T "\midrule \textbf{Panel B:}", nolabel) ///
	nonumber append posthead("`gap'") b(2) se label alignment(S S S) f ///
	nomtitles nogaps booktabs noobs compress star(* 0.10 ** 0.05 *** 0.01) ///
	nobaselevels keep(1.T 1.T#1.List 1.List) ///
	scalars("lin_p \hspace{0.1cm} $\alpha$(Long + T$\times\$Long > 0)" "N_clust \hspace{0.1cm} Clusters" "N \hspace{0.1cm} Observations") sfmt(2 0)

